home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_12 / allison / tbits.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-04  |  664 b   |  28 lines

  1. LISTING 8 - Illustrates the bits class template in a 16-bit environment
  2.  
  3. // tbits.cpp:     Set some bits and display the result
  4. #include <iostream.h>
  5. #include <stddef.h>
  6. #include <limits.h>
  7. #include <bits.h>
  8.  
  9. main()
  10. {
  11.     const size_t SIZE = CHAR_BIT * sizeof(int);
  12.     bits<SIZE> flags;
  13.     enum open_mode {in, out, ate, app, trunc, binary};
  14.  
  15.     flags.set(in);
  16.     flags.set(binary);
  17.     cout << "flags: " << flags << " (0x" << hex
  18.          << flags.to_ushort() << ")" << endl;
  19.     cout << "binary? "
  20.          << (flags.test(binary) ? "yes" : "no")
  21.          << endl;
  22.     return 0;
  23. }
  24.  
  25. Output
  26. flags: 0000000000100001 (0x21)
  27. binary? yes
  28.